#include "LinkList.h"
#include <stdio.h>
#include <stdlib.h>
#define N 20
static int cmp_int(const void *a, const void *b);
static void show_int(const void *a);

int main(int argc, char *argv[]) {

  LList *list = NULL;
  list_init(&list, sizeof(int));
  for (int i = 0; i < N; i++) {
    list_insert_back(list, &i);
  }

  list_traval(list, show_int);
  putchar('\n');

  show_int(list_get_data(list, 2));
  putchar('\n');
  show_int(list_get_data(list, 1));
  putchar('\n');

  int data_key = 0;
  list_del_by_data(list, &data_key, cmp_int);

  list_traval(list, show_int);
  putchar('\n');

  list_del_by_index(list, 2);
  list_traval(list, show_int);
  putchar('\n');

  list_mod(list, 3, &data_key);
  list_traval(list, show_int);
  putchar('\n');

  LNode *search_result = list_search(list, &data_key, cmp_int);
  show_int(search_result->data);
  putchar('\n');
  list_reverse(list);
  list_traval(list, show_int);
  putchar('\n');

  list_destory(&list);
}

static int cmp_int(const void *a, const void *b) {
  return *(const int *)a - *(const int *)b;
}
static void show_int(const void *a) { printf("%d  ", *(const int *)a); }
